<template>
  <div>
    <el-row type="flex">
      <el-form :inline="true">
        <el-form-item label="类加载器">
          <classloader-chose v-model="loaderName"  />
        </el-form-item>
        <el-form-item label="Maven Settings">
          <connect-chose module="maven" v-model="settings"/>
        </el-form-item>
      </el-form>
    </el-row>

    <pom-edit ref="pomValue" />

    <el-dialog append-to-body :visible.sync="dialog.visible" :title="dialog.title">
      <loaded-info :upload-response="dialog.response"/>
    </el-dialog>
  </div>
</template>

<script>
import PomEdit from '@/views/core/classloader/PomEdit'
import ClassloaderChose from '@/views/core/classloader/ClassloaderChose'
import loadedInfo from '@/views/core/classloader/loadedInfo'
import ConnectChose from '@/views/components/ConnectChose'

import core from '@/api/core'

export default {
  name: 'uploadPom',
  props: {
    classloaderName: String
  },
  components: {PomEdit, ClassloaderChose,ConnectChose, loadedInfo},
  data(){
    return {
      loaderName: null,
      dialog: {
        visible: false,
        title:'上传结果',
        response: {}
      },
      settings: null
    }
  },
  methods: {
    submit(){
      let pomValue = this.$refs.pomValue.getValue()
      return new Promise((resolve,reject) => {
        core.uploadContent(this.classloaderName,pomValue,this.settings).then(res => {
          this.dialog.response = res.data
          this.dialog.visible = true
          resolve()
        })
      })
    }
  },
  mounted() {
    this.loaderName = this.classloaderName
  },
  watch: {
    classloaderName: {
      handler(value){
        this.loaderName = value
      }
    }
  }
}
</script>

<style scoped>

</style>
